import os

srcdir = "data0"
destdir = "data1"

PAGE_TEMPLATE = """title="%s"
author="%s"
category="%s"
summary="%s"
minor="%s"
content=[=======[%s]=======]
"""


for page in os.listdir(srcdir) :
    os.mkdir(destdir+"/"+page)
    print page
    for version in os.listdir(srcdir+"/"+page) :
        src = open(srcdir+"/"+page+"/"+version).read().split("\n")
        output = PAGE_TEMPLATE % (src[0], src[1], src[2], src[3], src[4],
                                  "\n".join(src[5:]))
        out = open(destdir+"/"+page+"/"+version, "w")
        out.write(output)
        out.close()

